package com.choupin.choupin.controller;

import com.choupin.choupin.entity.JsonResult;
import com.choupin.choupin.entity.Prize;
import com.choupin.choupin.service.IPrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/prize")
public class PrizeController extends BaseController {

    @Autowired
    IPrizeService prizeService;

//    查看奖品
    @CrossOrigin
    @RequestMapping("/showprize")
    public JsonResult<List<Prize>> showPrize(@RequestBody Map<String,Object> data){
        JsonResult<List<Prize>> jsonResult=new JsonResult<>();
        System.out.println("奖品查询"+(String) data.get("phone")+","+(Integer) data.get("currentPage")+(Integer) data.get("pageSize"));
        List<Prize> list=prizeService.showPrize((String) data.get("phone"),(Integer) data.get("currentPage"),(Integer) data.get("pageSize"));
         jsonResult.setState(SUCCESS);
         jsonResult.setData(list);
         return jsonResult;
    }
//    更新奖品
    @CrossOrigin
    @RequestMapping("/updateprize")
    public JsonResult<Void> updatePrize(@RequestBody Map<String,Object> data){
        JsonResult<Void> jsonResult=new JsonResult<>();
        prizeService.updatePrize((Integer) data.get("id"));
        jsonResult.setState(SUCCESS);
        return jsonResult;
    }


}
